A cast is an explicit
conversion, which is a way to tell the compiler the intent to convert from one type to another.
void Method(object value)
{
int i;
i = (int)value; // Casting (explicit conversion) from float to int
}
In most cases, the compiler will be able to catch invalid casts between incompatible value types or reference types.
However, the compiler will not be able to detect invalid casts to interfaces.
What is the potential impact?
Invalid casts will lead to unexpected behaviors or runtime errors such as InvalidCastException.
Exceptions
No issue is reported if the interface has no implementing class in the assembly.